﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlutoStudio.Net.Processors.Security
{
    public class GenericPrincipal:IPrincipal
    {
        private string[] m_roles;
        private IIdentity m_identity;

        public GenericPrincipal(IIdentity identity,string[] roles)
        {
            m_roles = roles;
            m_identity = identity;
        }

        public virtual bool IsInRole(string role)
        {
            return m_roles!=null && m_roles.Any(r=>r.Equals(role));
        }

        public IIdentity Identity
        {
            get { return m_identity; }
        }
    }

    public class GenericIdentity : IIdentity
    {
        public GenericIdentity():this("","")
        {

        }

        public GenericIdentity(string name):this(name,"")
        {

        }

        public GenericIdentity(string name,string authenticationType)
        {
            this.AuthenticationType = authenticationType;
            this.Name = name;
        }

        public virtual string AuthenticationType { get; set; }

        public virtual bool IsAuthenticated
        {
            get { return !string.IsNullOrWhiteSpace(Name); }
        }

        public virtual string Name { get; set; }
    }

}
